import os

import tensorflow as tf

#  yapf: disable
column_names=[
    "uid",
    "user_city",
    "item_id",
    "author_id",
    "item_city",
    "channel",
    "finish",
    "like",
    "music_id",
    "device",
    "time",
    "duration_time"
]
column_defaults=[[''] for _ in column_names]
#  yapf: enable


def get_project_dir():
    """TODO: Docstring for get_project_dir.
    :returns: TODO

    """
    return os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))


project_dir = get_project_dir()


def get_train_file_names():
    """TODO: Docstring for get_train_file_names.
    :returns: TODO

    """
    dir_name = os.path.join(project_dir, 'resources', 'final_track1_train')
    file_names = os.listdir(dir_name)
    file_names = [
        os.path.join(dir_name, file_name) for file_name in file_names
    ]
    return file_names


def get_test_file_names():
    """TODO: Docstring for get_test_file_names.
    :returns: TODO

    """
    return [
        os.path.join(project_dir, 'resources',
                     'final_track1_test_no_anwser.txt')
    ]


def parse_csv():
    """TODO: Docstring for parse_csv.
    :returns: TODO

    """
    fields = tf.decode_csv([line],
                           record_defaults=column_defaults,
                           field_delim='\t')
    return dict(zip(column_names, fields))


def parse_finish_csv(line):
    """TODO: Docstring for parse_csv.

    :line: TODO
    :returns: TODO

    """
    fields = tf.decode_csv([line],
                           record_defaults=column_defaults,
                           field_delim='\t')
    features = dict(zip(column_names, fields))
    label = features.pop('finish')
    return features, tf.equal(label, '1')


def parse_like_csv(line):
    """TODO: Docstring for parse_csv.

    :line: TODO
    :returns: TODO

    """
    fields = tf.decode_csv([line],
                           record_defaults=column_defaults,
                           field_delim='\t')
    features = dict(zip(column_names, fields))
    label = features.pop('like')
    return features, tf.equal(label, '1')


def get_test_dataset():
    """TODO: Docstring for get_test_finish_dataset.
    :returns: TODO

    """
    test_file_names = get_test_file_names()
    dataset = tf.data.TextLineDataset(test_file_names)
    dataset = dataset.map(parse_csv, num_parallel_calls=os.cpu_count())
    return dataset


if __name__ == "__mai__":
    print(get_project_dir())
